[][src]Crate xpath_reader

Provides a convenient API to read from XML using XPath expressions.

This crate is mostly a wrapper around the crate sxd_xpath.

Examples

use xpath_reader::{Context, Reader};

let xml = r#"<?xml version="1.0"?><book xmlns="books" name="Neuromancer" author="William Gibson"><tags><tag name="cyberpunk"/><tag name="sci-fi"/></tags></book>"#;

let mut context = Context::new();
context.set_namespace("b", "books");

let reader = Reader::from_str(xml, Some(&context)).unwrap();

let name: String = reader.read("//@name").unwrap();
assert_eq!(name, "Neuromancer".to_string());

let publisher: Option<String> = reader.read("//@publisher").unwrap();
let author: Option<String> = reader.read("//@author").unwrap();
assert_eq!(publisher, None);
assert_eq!(author, Some("William Gibson".to_string()));

let tags: Vec<String> = reader.read("//b:tags/b:tag/@name").unwrap();
assert_eq!(tags, vec!["cyberpunk".to_string(), "sci-fi".to_string()]);

Re-exports

pub use self::reader::FromXml;
pub use self::reader::FromXmlOptional;
pub use self::reader::FromXmlResult;
pub use self::reader::Reader;

Modules

expression

XPath expression convenience typing.

reader

XPath based document parsing.

Structs

Context

Contains the context in which XPath expressions are executed. The context contains functions, variables, and namespace mappings.

Error

The error type used throughout the crate.

Enums

ErrorKind

Describes the kind of the error.